import loginView from '$v/login'
import { loginRequest } from '../api/admin'
export default (req,res)=>{
    res.render(loginView())
    document.loginForm.loginBtn.onclick = async function (e) {
        e.preventDefault();
        const adminNameValue = document.loginForm.adminName.value;
        const passwordValue = document.loginForm.passWord.value;

        //发送登录请求
        try {
            const loginRe = await loginRequest({
                adminName: adminNameValue,
                password: passwordValue
            })
            console.log(loginRe);
            //当登录成功以后 把token保存在本地存储中
            localStorage.setItem("user_token", loginRe.token)
            //跳转到adv界面
            router.go("/adv")
        } catch (e) {
            alert(e.message)
        }
    }
}